import request from '@/utils/request'

// 根据订单生成报关单草稿
export function generateFromOrders(data) {
  return request({
    url: '/fiscale/declaration/generateFromOrders',
    method: 'post',
    data: data
  })
}

// 智能填充商品信息
export function autoFillProductInfo(productSku) {
  return request({
    url: '/fiscale/declaration/autoFill/' + productSku,
    method: 'get'
  })
}

// 数据校验
export function validateDeclaration(data) {
  return request({
    url: '/fiscale/declaration/validate',
    method: 'post',
    data: data
  })
}

// 保存为草稿（使用现有的新增/修改接口）
export function saveDraft(data) {
  if (data.declarationId) {
    return request({
      url: '/fiscale/declaration',
      method: 'put',
      data: data
    })
  } else {
    return request({
      url: '/fiscale/declaration',
      method: 'post',
      data: data
    })
  }
}

// 申报到海关
export function submitToCustoms(declarationId) {
  return request({
    url: '/fiscale/declaration/submitToCustoms/' + declarationId,
    method: 'post'
  })
}

// 获取校验规则（暂时不实现）
export function getValidationRules(tradeMode, hsCode) {
  return request({
    url: '/fiscale/declaration/validationRules',
    method: 'get',
    params: {
      tradeMode,
      hsCode
    }
  })
}